var searchType=-1;
var style=0;



jQuery("#grid").jqGrid({        
   	url:'white_url_manager.php',
	datatype: "json",
	height: 200,
   	colNames:['记录编号','url地址'],
   	colModel:[
   		{name:'ID',index:'ID', editable:true,editoptions:{readonly:true,size:10},width:100},
   		{name:'URL',index:'URL',editable:true, width:200,formoptions:{ rowpos:3, label: "名称", elmprefix:"(*)"},editrules:{required:true}}
   	],
    width:"100%",
    rowNum:20,
    rowList:[10,20,30],
   	 mtype: "POST",
   	 pager: jQuery('#pgrid'),
   	 sortname: 'ID',
   	 viewrecords: true,
   	 multiselect:true,
   	 sortable: true,
    sortorder: "asc",
	 editurl:"white_url_manager.php?style=2"
});


$("#edit").click(function(){ var gr = jQuery("#grid").jqGrid('getGridParam','selrow'); 
if( gr != null ) jQuery("#grid").jqGrid('editGridRow',gr,{height:280,reloadAfterSubmit:true}); 
else alert("Please Select Row"); });




$("#del").click(function(){ 
var gr = jQuery("#grid").jqGrid('getGridParam','selarrrow');
var ids=new Array();
if( gr != null ){
var len = gr.length;
for (var i=0;i<len;i++)
{
var ret = jQuery("#grid").jqGrid('getRowData',gr[i]);
ids[i]=ret.ID;
}

jQuery("#grid").jqGrid('delGridRow',ids,{reloadAfterSubmit:true});
}
 
else alert("Please Select Row to delete!"); 
});

//functions 
function add()
{


    style=1;

	 var rev_mask=jQuery("#receiver").val();
    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;


    
    if (rev_mask!="")
    {
     
    try{
    jQuery("#grid").jqGrid('setGridParam',{url:"white_url_manager.php?q=1&rev_mask="+rev_mask+"&style="+style,page:1}).trigger('reloadGrid');
    jQuery("#grid").jqGrid('setGridParam',{url:"white_url_manager.php"}).trigger('reloadGrid');
    }
    catch(err)
    {
	jQuery("#grid").jqGrid('setGridParam',{url:"white_url_manager.php"}).trigger('reloadGrid'); 
   }


    }
   else{
     alert("请正确输入");
   }
}
function complexSearch(){
   	$( "#s" ).dialog( { 
	       width:350,  
          height:250, 
	       buttons: { 
	      "取消": function() { $(this).dialog("close"); },
	      "重置": function(){
	      jQuery("#receiver1").attr("value","");
	      
	      },
	      "提交":function(){

	           style=0
	           var rev_mask=jQuery("#receiver1").val();
      jQuery("#grid").jqGrid('setGridParam',{url:"white_url_manager.php?q=1&rev_mask="+rev_mask+"&style="+style,page:1}).trigger('reloadGrid'); 
	            jQuery("#grid").jqGrid('setGridParam',{url:"white_url_manager.php"}).trigger('reloadGrid'); 
	         }
	         },
	       close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			} });
   

}
function uploadFile()
{
    
	$( "#file" ).dialog( { 
	       width:350,  
          height:250, 
	       buttons: { 
	      "取消": function() { $(this).dialog("close");style=0; },
	      "提交":function(){
	            style=0;
	            jQuery("#grid").jqGrid('setCaption',"详细: ") .trigger('reloadGrid'); 
	         }
	         },
	       close: function() {
	           style=0;
				allFields.val( "" ).removeClass( "ui-state-error" );
			} });
}










